package model

import (
	"github.com/lab-online/internal/course/entity"
	"github.com/lab-online/pkg/model"
)

type Experiment struct {
	model.BaseModel
	Name        string `gorm:"type:varchar(100);not null"`
	Description string `gorm:"type:varchar(256)"`
	Queue       string `gorm:"type:varchar(64);not null;unique"`
}

func (e *Experiment) ToEntity() entity.ExperimentEntity {
	return entity.NewExperimentEntity(
		entity.WithExpID(e.ID),
		entity.WithExpName(e.Name),
		entity.WithExpDescription(e.Description),
		entity.WithExpQueue(e.Queue),
	)
}

type ExperimentOption func(*Experiment)

func NewExperiment(options ...ExperimentOption) *Experiment {
	e := &Experiment{}
	for _, option := range options {
		option(e)
	}
	return e
}

func WithExperimentID(id uint) ExperimentOption {
	return func(e *Experiment) {
		e.ID = id
	}
}

func WithExperimentEntity(experiment entity.ExperimentEntity) ExperimentOption {
	return func(e *Experiment) {
		e.ID = experiment.GetID()
		e.Name = experiment.GetName()
		e.Description = experiment.GetDescription()
		e.Queue = experiment.GetQueue()
	}
}
